<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{common/public::common-public}">
    <meta charset="UTF-8">
    <title>管理员主界面</title>
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<style>


</style>
<div class="header" th:insert="~{common/kuangjia::header}"></div>
<div class="diceng">
<div class="caidan">
<ul>
<li><a th:href="@{/manong//managermain}">首页</a></li>
<li><a th:href="@{/manong/getAllCourse}">选课系统</a></li>
<li><a th:href="@{/manong/gradeManager}">成绩管理</a></li>
<li><a th:href="@{/manong/active}">活动公告</a></li>
<li><a th:href="@{/manong/message}">消息中心</a></li>
<li><a th:href="@{/manong/exit}">退出登录</a></li>
</ul>
</div>

<div class="main">

<table>
        <tr>
            <th>课程号</th>
            <th>课程名</th>
            <th>授课教师</th>
            <th>学期</th>
            <th>上课时间</th>
            <th>教室</th>
            <th>星期</th>
            <th>专业</th>
            <th>学分</th>
            <th>操作</th>
        </tr>
        <!-- <tbody id="mybody">
        
        
        </tbody> 
        </table>
        <form th:action="@{/manong/getpageInfo_course}" method="GET">
    <input type="text" name="pageNum" value="1">
    <input type="text" name="size" value="5">
    <input type="submit" value="Submit">
</form>-->
        
            <tr th:each="u:${pageInfo.list}">
            <td th:text="${u.cno}"></td>
            <td th:text="${u.course}"></td>
            <td th:text="${u.teacher}"></td>
            <td th:text="${u.semester}"></td>
            <td th:text="${u.time}"></td>
            <td th:text="${u.classroom}"></td>
            <td th:text="${u.week}"></td>
            <td th:text="${u.speciality}"></td>
            <td th:text="${u.credit}"></td>
            <td>
                <a th:href="@{/manong/update(cno=${u.cno})}"><button>修改</button></a> <br>
                <a th:href="@{/manong/deleteLesson(cno=${u.cno})}" onclick="return confirm('确定要删除吗')"><button>删除</button></a>
            </td>
        </tr>
    </table>
             <span th:text="'总共'+${pageInfo.pages}+'页,共'+${pageInfo.total}+'条数据。每页'"></span>
         <select id="changePageSize"
                onchange="changePageSize()">
            <option>选择每页条数...</option>
            <option>1</option>
            <option>2</option>
            <option>3</option>
            <option>4</option>
            <option>5</option>
         </select> 条
                 <div class="ul_style">
            <ul>
                <li>
                    <a th:href="@{/manong/getAllCourse(page=1,size=${pageInfo.pageSize})}"
                        aria-label="Previous">首页</a></li>
                <li>
                    <a th:href="@{/manong/getAllCourse(page=${pageInfo.pageNum}-1,size=${pageInfo.pageSize})}">上一页</a>
                </li>
			<th:block th:each="pa:${#numbers.sequence(1,pageInfo.pages)}">
                <li>
                    <a th:href="@{/manong/getAllCourse(page=${pa},size=${pageInfo.pageSize})}">[[${pa}]]</a>
                </li>
            </th:block>
                <li>
                    <a th:href="@{/manong/getAllCourse(page=${pageInfo.pageNum}+1,size=${pageInfo.pageSize})}">下一页</a>
                </li>
                <li>
                     <a th:href="@{/manong/getAllCourse(page=${pageInfo.pages},size=${pageInfo.pageSize})}"
                        aria-label="Next">尾页</a></li>
             </ul>
        </div>
         
    
</div>
</div>
<script th:inline="javascript">
function changePageSize() {
    //获取下拉框的值
    var pageSize = $("#changePageSize").val();

    //向服务器发送请求，改变没页显示条数
    location.href = "http://localhost:8080/manong/getAllCourse?page=1&size=" + pageSize;
}

$("#find").keydown(function (e) {
    if (e.keyCode === 13) {
        $("#sub").click();
    }
});
$(document).ready(function () {
    // 选择框
    $(".select2").select2();

    // WYSIHTML5编辑器
    $(".textarea").wysihtml5({
        locale: 'zh-CN'
    });
});

// 设置激活菜单
function setSidebarActive(tagUri) {
    var liObj = $("#" + tagUri);
    if (liObj.length > 0) {
        liObj.parent().parent().addClass("active");
        liObj.addClass("active");
    }
}

$(document).ready(function () {

    // 激活导航位置
    setSidebarActive("admin-datalist");

    // 列表按钮
    $("#dataList td input[type='checkbox']").iCheck({
        checkboxClass: 'icheckbox_square-blue',
        increaseArea: '20%'
    });
    // 全选操作
    $("#selall").click(function () {
        var clicks = $(this).is(':checked');
        if (!clicks) {
            $("#dataList td input[type='checkbox']").iCheck("uncheck");
        } else {
            $("#dataList td input[type='checkbox']").iCheck("check");
        }
        $(this).data("clicks", !clicks);
    });
});


/* var xhr = new XMLHttpRequest();
console.log(xhr)
xhr.open("GET", "/manong/getpageInfo_course")
xhr.send()
xhr.onreadystatechange=function(){
	 if(xhr.readyState==4){
		 //console.log("解析完成",JSON.parse(xhr.responseText))
		var course=xhr.responseText;
		 course=JSON.parse(course);
		 console.log(course)
		 var tbody=document.getElementById('mybody')
		  tbody.innerHTML = '';
		 for(var i=0;i<course.length;i++){
			 if(course[i].cno){
		 var tr=document.createElement('tr')
		 
		 for(var k in course[i]){
		var td=document.createElement('td')
		 td.innerHTML=course[i][k];
	
		 tr.appendChild(td)
		 }
		 tbody.appendChild(tr)
		 }
		 }
	 }
} */

</script> 
</body>
</html>